package com.wz.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wz.common.utils.text.Convert;
import com.wz.device.entity.BasRoadway;
import com.wz.device.mapper.BasRoadwayMapper;
import com.wz.device.service.BasRoadwayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author qiqi
 * @since 2021-10-22
 */
@Service
public class BasRoadwayServiceImpl extends ServiceImpl<BasRoadwayMapper, BasRoadway> implements BasRoadwayService {


    @Autowired
    private BasRoadwayMapper basRoadwayMapper;

    @Override
    public List<BasRoadway> selectBasRoadwayList(BasRoadway basRoadway) {
        // 生成数据权限过滤条件
        return basRoadwayMapper.selectBasRoadwayList(basRoadway);
    }

    @Override
    public int insertBasRoadway(BasRoadway basRoadway) {
        try {
            // 新增巷道信息
            String s = String.valueOf(System.currentTimeMillis());
            String substring = s.substring(s.length() - 6);
            basRoadway.setId(BigDecimal.valueOf(Long.parseLong(substring)));
            int rows = basRoadwayMapper.insertBasRoadway(basRoadway);
            return rows;
        } catch (NumberFormatException e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public BasRoadway selectBasRoadway(String id) {
        return basRoadwayMapper.selectBasRoadwayById(id);
    }

    @Override
    public int updateBasRoadway(BasRoadway basRoadway) {
        try {
            return basRoadwayMapper.updateBasRoadway(basRoadway);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int deleteBasRoadwayByIds(String ids) {
        try {
            String[] deviceRaodWayIds = Convert.toStrArray(ids);
            return basRoadwayMapper.deleteBasRoadwayByIds(deviceRaodWayIds);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public int changeLocked(BasRoadway basRoadway) {
        try {
            return basRoadwayMapper.updateBasRoadway(basRoadway);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
